Introduce `Context::host_triple` method
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 13 Jul 2016 16:20:47 +0000 (19:20 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 13 Jul 2016 16:20:47 +0000 (19:20 +0300)
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/custom_build.rs

index f73b9cada9f8330f28079d46b8141a1207448d64..53678eb5b1f0739177f2a6e51ad29488f139ee9f 100644 (file)
@@ -264,11 +264,21 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         }
     }
 
+    /// Return the host triple for this context
+    pub fn host_triple(&self) -> &str {
+        &self.config.rustc_info().host[..]
+    }
+
     /// Return the target triple which this context is targeting.
     pub fn target_triple(&self) -> &str {
         &self.target_triple
     }
 
+    /// Requested (not actual) target for the build
+    pub fn requested_target(&self) -> Option<&str> {
+        self.build_config.requested_target.as_ref().map(|s| &s[..])
+    }
+
     /// Get the metadata for a target in a specific profile
     pub fn target_metadata(&self, unit: &Unit) -> Option<Metadata> {
         let metadata = unit.target.metadata();
@@ -600,8 +610,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             None => return true,
         };
         let (name, info) = match kind {
-            Kind::Host => (&self.config.rustc_info().host, &self.host_info),
-            Kind::Target => (&self.target_triple, &self.target_info),
+            Kind::Host => (self.host_triple(), &self.host_info),
+            Kind::Target => (self.target_triple(), &self.target_info),
         };
         platform.matches(name, info.cfg.as_ref().map(|cfg| &cfg[..]))
     }
@@ -632,11 +642,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
     /// Number of jobs specified for this build
     pub fn jobs(&self) -> u32 { self.build_config.jobs }
 
-    /// Requested (not actual) target for the build
-    pub fn requested_target(&self) -> Option<&str> {
-        self.build_config.requested_target.as_ref().map(|s| &s[..])
-    }
-
     pub fn lib_profile(&self, _pkg: &PackageId) -> &'a Profile {
         let (normal, test) = if self.build_config.release {
             (&self.profiles.release, &self.profiles.bench_deps)
index c20eeca12e163abde543cb4d1542cc81c3ad5e59..868f07a8f5d96c1b1629af34de76bd60272ea3f7 100644 (file)
@@ -106,13 +106,13 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
      .env("CARGO_MANIFEST_DIR", unit.pkg.root())
      .env("NUM_JOBS", &cx.jobs().to_string())
      .env("TARGET", &match unit.kind {
-         Kind::Host => &cx.config.rustc_info().host[..],
+         Kind::Host => cx.host_triple(),
          Kind::Target => cx.target_triple(),
      })
      .env("DEBUG", &profile.debuginfo.to_string())
      .env("OPT_LEVEL", &profile.opt_level.to_string())
      .env("PROFILE", if cx.build_config.release {"release"} else {"debug"})
-     .env("HOST", &cx.config.rustc_info().host)
+     .env("HOST", cx.host_triple())
      .env("RUSTC", &cx.config.rustc())
      .env("RUSTDOC", &cx.config.rustdoc());